package com.appinfo.util;

import java.util.List;

/**
 * 封装分页实体类
 * 
 * @author acer
 *
 */
public class Page<T> {

	private int currPageNo = 1;// 当前页数
	private int pageSize = 10;// 每页显示条数
	private int totalCount;// 总记录数
	private int totalPageCount;// 总页数
	private List<T> dataList;// 每页显示的数据

	public Page(Integer currPageNo) {
		this.currPageNo = currPageNo == null ? 1 : currPageNo;
	}

	public Page() {
	}

	/**
	 * 判断上一页
	 * 
	 * @return
	 */
	public boolean hasPrevPage() {
		return this.currPageNo > 1;
	}

	/**
	 * 判断下一页
	 * 
	 * @return
	 */
	public boolean hasNextPage() {
		return this.currPageNo < this.totalPageCount;
	}

	/**
	 * 获取上一页
	 * 
	 * @return
	 */
	public int getPrevPage() {
		return this.currPageNo - 1;
	}

	/**
	 * 获取下一页
	 * 
	 * @return
	 */
	public int getNextPage() {
		return this.currPageNo + 1;
	}

	/**
	 * 获取起始页
	 * 
	 * @return
	 */
	public int getStartRow() {
		return (this.getCurrPageNo() - 1) * this.getPageSize();
	}

	public int getCurrPageNo() {
		return currPageNo;
	}

	public void setCurrPageNo(int currPageNo) {
		this.currPageNo = currPageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		if (this.totalCount > 0) {
			// 计算总页数
			this.totalPageCount = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize
					: this.totalCount / this.pageSize + 1;
		}
	}

	public int getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public List<T> getDataList() {
		return dataList;
	}

	public void setDataList(List<T> dataList) {
		this.dataList = dataList;
	}

}
